package com.yk._14Volatile;

/**
 * @author xuxing
 * @data 2020/4/20
 */

import java.util.concurrent.TimeUnit;

/**
 * volatile
 *      1.保证可见性
 *      2.不保证原子性
 *      3.禁止指令重排
 */

//证明保证可见性
public class _01Volatile {
    private static volatile int num = 0;

    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            System.out.println("开始");
            while(num==0){}
            System.out.println("结束");

        }).start();

        TimeUnit.SECONDS.sleep(1);

        num = 1;
    }
}
